Date.prototype.toLocaleString = function(flag) {
    if(flag){
        var iWeek = this.getDay();
        if( iWeek === 0 ) iWeek = '星期日';
        if( iWeek === 1 ) iWeek = '星期一';
        if( iWeek === 2 ) iWeek = '星期二';
        if( iWeek === 3 ) iWeek = '星期三';
        if( iWeek === 4 ) iWeek = '星期四';
        if( iWeek === 5 ) iWeek = '星期五';
        if( iWeek === 6 ) iWeek = '星期六';
        return ( this.getFullYear()+'年'+two(this.getMonth() + 1 )+ "月" + two(this.getDate()) + "日" +" "+iWeek+' '+ two(this.getHours()) + ":" + two(this.getMinutes()) );
    }else{
        return (two(this.getMonth() + 1 )+ "月" + two(this.getDate()) + "日" +" "+ two(this.getHours()) + ":" + two(this.getMinutes()));
    }

};

//格式化日期
Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

//日期转格式 年-月-日
function replaceDate(dateStr,set){
    var oDate = new Date()
    if (set) {
        oDate = new Date(set)
    } else{
        oDate = new Date()
    }
    var year = oDate.getFullYear()+'年';
    var month = oDate.getMonth()+1+'月';
    var day;
    var finalDate;
    if (dateStr=="y-m-d") {
        day = oDate.getDate()+'日';
        finalDate = [year,month,day].join('')
    }else if(dateStr=="y-m"){
        finalDate = [year,month].join('')
    }else if(dateStr=="m-d"){
        day = oDate.getDate()+'日';
        finalDate = [month,day].join('')
    }
    return finalDate;
}

function imgClass(ev){
    var tar = ev.target;
    if (tar.parentNode.getAttribute("data-size")) {
        tar.parentNode.setAttribute("data-size",tar.width+"x"+tar.height)
    }
    if (tar.width < tar.height) {
        tar.className = 'imgWidth'
    }else{
        tar.className = 'imgHeight'
    }
}

//获取url的参数
function GetQueryString(name){
//    // var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
//    var url  = window.location.search.substr(1);
//
//    // url = 'abc=124&token=123456';
//    //var reg = /(\w+)=(\w+)/ig;
//    var params = url.split('&');
//    params.forEach(function (element) {
//        var item = element.split('=');
//        if(item[0] === name){
//            return item[1];
//        }
//    });

    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]);
	return null;
    //if(r!=null)return  decodeURI(r[2]); return null;
}

function two(n){
    return n<10? "0"+n : ''+n;
}